<?php
ob_start();
?>
<?php
include ('encabezado.php');
?>
<form action="" method="POST">
<br><br>
<table border="2" align="center">
<tr>

<td align="center">
<h2>Create Student<br></h2>
Name: <br>
<input type="text" name="name"><br><br>
Surname: <br>
<input type="text" name="surname"><br><br>
Password: <br>
<input type="password" name="password"><br>
<br><input type="submit" value="Create">
<input type="hidden" name="submitted" value="true">
<?php
if (isset($_POST['submitted']))
{
 if (!empty($_POST['name']) == true && !empty($_POST['surname']) == true && !empty($_POST['password']) == true)
 {
  //coger id del grupo
  //session_start();
  $$choosengroup = $_SESSION['choosen'];
  $conexion = mysql_connect("$ip", "$userdb", "$passworddb");
   mysql_select_db("$db", $conexion);
   $q = "select * from Groups where Name='$choosengroup'";
   $lasid= mysql_query($q, $conexion) or die ("problema con query");
    while ($registro = mysql_fetch_array($lasid))
    {
     $grupoid=$registro['GroupID'];
    }
  //insertar alumno
  $name = $_POST['name'];
  $surname = $_POST['surname'];
  $info = $_POST['password'];
  $password = md5($_POST['password']);
  $h= "insert into Users (Name,Surname,Password,GroupID, Info) values ('$name','$surname','$password','$grupoid', '$info')";
   if (mysql_query($h, $conexion))
    {
     echo '<br> Inserted.';
    }
    else
    {
     echo '<br> Not inserted.';
    }
  
 }
 else
 {
  echo '<br> Fill all fields.';
 }
}
?>
</td></tr>
</table>
</form>
<?php
include ('pie.php');
?>
<?php
ob_end_flush();
?>